package org.belkodevelop.admin.dao;

import org.belkodevelop.user.domain.User;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class AdminDAOImpl implements AdminDAO {

    @Autowired
    private SessionFactory sessionFactory;

    @Override
    public void enableUser(long userId) {
        Query query = sessionFactory.getCurrentSession().
                createQuery("update User u set u.enable = true where u.id= :id");
        query.setParameter("id", userId);
        query.executeUpdate();
    }

    @Override
    public void disableUser(long userId) {
        Query query = sessionFactory.getCurrentSession().
                createQuery("update User u set u.enable = false where u.id= :id");
        query.setParameter("id", userId);
        query.executeUpdate();
    }

    @Override
    public void removeUser(long userId) {
        Query query = sessionFactory.getCurrentSession().
                createQuery("delete from User where id = :id");
        query.setParameter("id", userId);
        query.executeUpdate();
    }

}
